import React, {Component} from 'react';
import './App.css';
import Utils, {getPersons, persons} from "./Utils";
import memoizeOne from 'memoize-one';

const utils = new Utils();

class MemoizeOne extends Component {

  constructor(p) {
    super(p);
    this.state = {
      num: 1
    };
    this.handleAddClick = this.handleAddClick.bind(this);
  }
  mFilter = memoizeOne(this.filter);

  handleAddClick() {
    this.setState(this.state);
  }

  filter(persons) {
    return persons.filter(p => p.id >= 18);
  }

  render() {
    // let persons = getPersons(1000000);
    console.log(persons)
    utils.time();
    let mPersons = this.mFilter(persons);
    utils.time('mFilter耗时');
    let fPersons = this.filter(persons);
    utils.time('filter耗时');
    return (
        <>
          <div className='App'>
            <button onClick={this.handleAddClick}>测试</button>
          </div>
          {/*{fPersons.map(p => <div>{p.id}</div>)}*/}
        </>

    );
  }
}

export default MemoizeOne;
